﻿namespace jLight
{
    /// <summary>
    /// Class to handle 
    /// </summary>
    public class jQuerySelector
    {
        private readonly string _internalSelector;
        private readonly bool _canBeCombined;

        public jQuerySelector(string selector, bool canBeCombined)
        {
            _internalSelector = selector;
            _canBeCombined = canBeCombined;
        }

        public jQuerySelector(string selector) : this(selector, true) { }

        public static implicit operator jQuerySelector(string str)
        {
            return new jQuerySelector(str);
        }
        public override string ToString()
        {
            return (string) this;
        }
        public static implicit operator string(jQuerySelector str)
        {
            return str._internalSelector;
        }

        public static jQuerySelector operator +(jQuerySelector a, jQuerySelector b)
        {
            if (!a._canBeCombined) return a;
            if (!b._canBeCombined) return b;

            if (b._internalSelector[0] == ':')
                return a._internalSelector + b._internalSelector;
            return a._internalSelector + " " + b._internalSelector;
        }
    }
}